package com.rf.richfitwheel.sysbill.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rf.richfitwheel.common.utils.StringUtils;
import com.rf.richfitwheel.sysbill.dao.SysCustomerAccountMapper;
import com.rf.richfitwheel.sysbill.model.SysCustomerAccount;
import com.rf.richfitwheel.sysbill.service.SysCustomerAccountService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rf.richfitwheel.utils.PageJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wangTao
 * @since 2024-06-17
 */
@Service
public class SysCustomerAccountServiceImpl extends ServiceImpl<SysCustomerAccountMapper, SysCustomerAccount> implements SysCustomerAccountService {

    @Autowired
    private SysCustomerAccountMapper sysCustomerAccountMapper;
    @Override
    public PageJson pageJson(SysCustomerAccount sysCustomerAccount) {
        Page<SysCustomerAccount> page = new Page<>(sysCustomerAccount.getPageNum(), sysCustomerAccount.getPageSize());
        QueryWrapper<SysCustomerAccount> queryWrapper = new QueryWrapper<>();
        //客商名称
        if (StringUtils.isNotBlank(sysCustomerAccount.getCustomerName())) {
            queryWrapper.like("customer_name",sysCustomerAccount.getCustomerName());
        }
        //银行账户
        if (StringUtils.isNotBlank(sysCustomerAccount.getBankAccount())) {
            queryWrapper.like("bank_account",sysCustomerAccount.getBankAccount());
        }
        //客商类型
        if (StringUtils.isNotBlank(sysCustomerAccount.getCustomerType())) {
            queryWrapper.eq("customer_type",sysCustomerAccount.getCustomerType());
        }
        //内部外部
        if (StringUtils.isNotBlank(sysCustomerAccount.getInteriorWithout())) {
            queryWrapper.eq("interior_without",sysCustomerAccount.getInteriorWithout());
        }
        Page<SysCustomerAccount> pageData = sysCustomerAccountMapper.selectPage(page, queryWrapper);
        return PageJson.of(pageData);
    }
}
